package com.hele.sts.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.pub.ConnectDB;
import com.hele.sts.pub.SpringContextHolder;

public class BMCxqxDao
{
	static Logger logger = LoggerFactory.getLogger(BMCxqxDao.class);
  static String TABLE = "bm_cxqx";
  
  public static String getCxqx(String cxqx)
  {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = null;
    ConnectDB connsyb = null;
    String content = null;
    sql = "SELECT content FROM " + TABLE + " WHERE code = '" + cxqx + "' ";
    try
    {
      connsyb = SpringContextHolder.getBean(ConnectDB.class);
      conn = connsyb.getConnection();
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();
      if (rs.next())
      {
        content = rs.getString("content");
        String str1 = content;return str1;
      }
    }
    catch (SQLException localSQLException) {}finally
    {
    	DbClose.freeResultSet(rs);
      DbClose.freePreparedStatement(pstmt);
      DbClose.freeConnection(conn);
      System.out.println(content);
    }
    return cxqx;
  }
  
  public static List getCxqxList()
  {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = null;
    ConnectDB connsyb = null;
    List list = null;
    sql = "SELECT code,content FROM " + TABLE + " WHERE 1=1 ";
    try
    {
      connsyb = SpringContextHolder.getBean(ConnectDB.class);
      conn = connsyb.getConnection();
      pstmt = conn.prepareStatement(sql);
      int i = 1;
      rs = pstmt.executeQuery();
      list = new ArrayList();
      while (rs.next()) {
        list.add(rsToBean(rs));
      }
    }
    catch (SQLException e)
    {
      logger.info("db error", e);
    }
    finally
    {
      DbClose.freeResultSet(rs);
      DbClose.freeStatement(pstmt);
      DbClose.freeConnection(conn);
    }
    return list;
  }

private static Map rsToBean(ResultSet rs) throws SQLException {
	Map map = new HashMap();
	map.put("code", rs.getString("code"));
	map.put("content", rs.getString("content"));
	return map;
}
}
